package com.example.tests;

import static org.testng.Assert.assertEquals;

import java.util.Collections;
import java.util.List;
import org.testng.annotations.Test;

public class PersonCreationTest extends TestBase {

	@Test(dataProvider = "randomValidPersonGenerator")
	public void testPersonCreationWithValidData(PersonData person) throws Exception {
		app.getNavigationHelper().openMainPage();
		
		// save old state
		List<PersonData> oldList = app.getPersonHelper().getPersons();
		
		// actions
		app.getPersonHelper().openAddPersonPage();
		app.getPersonHelper().fillSelectsRandomly(person);
		app.getPersonHelper().fillAddPersonForm(app, person);
		app.getPersonHelper().submitPersonCreation();
		app.getNavigationHelper().retutnToMainPage();

		// save new state
		List<PersonData> newList = app.getPersonHelper().getPersons();

		// compare
		oldList.add(person);
		Collections.sort(oldList);
		assertEquals(newList, oldList);

	}
}